package com.wenbai.servicelightluxurystickers.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.wenbai.servicelightluxurystickers.common.RedisConstants;
import com.wenbai.servicelightluxurystickers.entity.StickPost;
import com.wenbai.servicelightluxurystickers.mapper.StickPostMapper;
import com.wenbai.servicelightluxurystickers.service.StickPostService;
import com.wenbai.servicelightluxurystickers.utils.RedisUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class StickPostImpl implements StickPostService {

    @Autowired
    private StickPostMapper stickPostMapper;
    @Autowired
    private RedisUtil redisUtil;

    @Override
    public List<StickPost> selectPost() {
        List<StickPost> posts = stickPostMapper.selectPostJoinUser();
        for (StickPost post : posts) {
            String key = RedisConstants.POST_VIEW_COUNT_KEY + post.getPostId();
            Integer redisViewCount = redisUtil.getInt(key);
            if (redisViewCount != null) post.setViewCount(redisViewCount);
        }
        return posts;
    }

    @Override
    public List<StickPost> selectForumUser(int postId) {
        return stickPostMapper.selectForumUser(postId);
    }

    @Override
    public List<StickPost> selectPostByUserId(int userId) {
        return stickPostMapper.selectPostByUserId(userId);
    }
}
